package com.oa.entities.flows;

import com.oa.domain.UndeleteEntity;
import com.oa.entities.User;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Entity
@Table(name = "oa_form")
public class Form extends UndeleteEntity<Long> {
    /**
     *
     */
    private static final long serialVersionUID = -129657264476408443L;

    public static final String FORM_TYPE_ID="typeId";

    public static final String FORM_INPUT_NAME="inputName";

    /** 名称 **/
    private String name;

    /** 输入框名称 **/
    private String inputName;

    /** 输入框的默认值 **/
    private String inputValue;

    /** 类型 **/
    private int inputType;

    /** 表单类型 **/
    private int fileType;

    /** 表单的说明 **/
    private List<String> optiones= new ArrayList<>();

    /** 表单验证方法 **/
    private String confiraction;

    /** 字段类型 **/
    private int dbType;

    /** 发布人 **/
    private User issue;

    /** 发布人的id **/
    private Long issueId;

    /** 模版 **/
    private AppType appType;

    private Long typeId;

    /** 宽 */
    private String w;

    /** 高 **/
    private String h;

    /** 虹口见 **/
    private String magnificent;

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return super.getId();
    }

    @Override
    public void setId(Long id) {
        super.setId(id);
    }

    @NotNull
    @Length(max = 64)
    @Column(name = "form_name",length = 64,nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @NotNull
    @Length(max = 64)
    @Column(name = "form_input_name",nullable = false,length = 64)
    public String getInputName() {
        return inputName;
    }

    public void setInputName(String inputName) {
        this.inputName = inputName;
    }

    @NotNull
    @Length(max = 250)
    @Column(name = "form_input_value",nullable = false,length = 250)
    public String getInputValue() {
        return inputValue;
    }

    public void setInputValue(String inputValue) {
        this.inputValue = inputValue;
    }

    @Column(name = "input_type",nullable = false)
    public int getInputType() {
        return inputType;
    }

    /**
     * @see com.oa.common.enums.apps.InputType
     * @param inputType
     */
    public void setInputType(int inputType) {
        this.inputType = inputType;
    }

    @Column(name = "file_type",nullable = false)
    public int getFileType() {
        return fileType;
    }

    public void setFileType(int fileType) {
        this.fileType = fileType;
    }


    public String getConfiraction() {
        return confiraction;
    }

    public void setConfiraction(String confiraction) {
        this.confiraction = confiraction;
    }

    @Column(name = "db_type",nullable = false)
    public int getDbType() {
        return dbType;
    }

    /**
     * 设置数据的类型
     *
     * @param dbType
     *
     * @see com.oa.common.enums.apps.DbType
     */
    public void setDbType(int dbType) {
        this.dbType = dbType;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "issue_id",updatable = false,nullable = false,insertable = false)
    public User getIssue() {
        return issue;
    }

    public void setIssue(User issue) {
        this.issue = issue;
    }

    @Column(name = "issue_id")
    public Long getIssueId() {
        return issueId;
    }

    public void setIssueId(Long issueId) {
        this.issueId = issueId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type_id",nullable = false,updatable = false,insertable = false)
    public AppType getAppType() {
        return appType;
    }

    public void setAppType(AppType appType) {
        this.appType = appType;
    }

    @NotNull
    @Length(max = 32)
    @Column(name = "weight",length = 32,nullable = false)
    public String getW() {
        return w;
    }

    public void setW(String w) {
        this.w = w;
    }

    @NotNull
    @Length(max = 32)
    @Column(name = "height",nullable = false,length = 32)
    public String getH() {
        return h;
    }

    public void setH(String h) {
        this.h = h;
    }

    @Column(name = "app_magnificent")
    public String getMagnificent() {
        return magnificent;
    }

    public void setMagnificent(String magnificent) {
        this.magnificent = magnificent;
    }

    @Override
    public String toString() {
        return "From{" +
                "name='" + name + '\'' +
                ", inputName='" + inputName + '\'' +
                ", inputValue='" + inputValue + '\'' +
                ", inputType=" + inputType +
                ", fileType=" + fileType +
                ", confiraction='" + confiraction + '\'' +
                ", dbType=" + dbType +
                ", issue=" + issue +
                ", issueId=" + issueId +
                ", appType=" + appType +
                ", w='" + w + '\'' +
                ", h='" + h + '\'' +
                ", magnificent='" + magnificent + '\'' +
                '}';
    }

    @Column(name = "type_id")
    public Long getTypeId() {
        return typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    @ElementCollection(fetch = FetchType.EAGER)
    @JoinTable(name = "oa_form_option")
    public List<String> getOptiones() {
        return optiones;
    }

    public void setOptiones(List<String> optiones) {
        this.optiones = optiones;
    }



}
